var menuTree;
var oTable;
$(function() {
			var setting = {
				view : {
					selectedMulti : false
				},
				callback : {
					onClick : function(event, treeId, treeNode, clickFlag) {

						oTable.gridSearch([{
									name : 'id',
									value : treeNode.id
								}]);
					}
				},
				async : {
					enable : true,
					url : "${_BASE_PATH}/system/menu/tree"
				}
			};
			menuTree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			menuTree.selectNode(menuTree.getNodeByParam("id", 0, null));

			oTable = $('#menutable').initDT({
						"sAjaxSource" : "${_BASE_PATH}/system/menu/query",
						"check" : "multi"
					});

			$("#menutreeRefresh").click(function() {
						var node = menuTree.getNodeByParam("id", 0, null);
						menuTree.reAsyncChildNodes(node, "refresh");
					});

			$("#newMenuBtn").click(function() {
						$.dialog({
									id : "newMenuDialog",
									url : "${_BASE_PATH}/static/system_menu_newMenu"
								})
					});

			$("#modifyMenuBtn").click(function() {

						if (oTable.getSelectedIds().length != 1) {
							$.alert("只能修改一个菜单。");
							return;
						}
						$.dialog({
									id : "modifyMenuDialog",
									url : "${_BASE_PATH}/system/menu/get",
									data : {
										id : oTable.getSelectedIds()[0]
									}
								});

					});

			$("#delMenuBtn").click(function() {
				if (oTable.getSelectedIds().length == 0) {
					$.alert("请选择要删除的菜单。");
					return;
				}

				$.confirm("确定要删除所选择的菜单吗，如果菜单下还有子菜单都会被删除？", function() {
							$.ajax({
										url : "${_BASE_PATH}/system/menu/del",
										data : {
											ids : oTable.getSelectedIds()
													.toString()
										},
										success : function(result) {
											oTable.gridReload();
										}
									});
						})
			});
			$("#selectall").click(function() {
						oTable.selectAllRow();
					});
			$("#cancelall").click(function() {
						oTable.unSelectAllRow();
					});
		});